package cn.stylefeng.guns.modular.tcpconnection.controller;

import cn.stylefeng.guns.modular.tcpconnection.entity.DeviceConnect;
import cn.stylefeng.guns.modular.tcpconnection.pojo.request.DeviceConnectRequest;
import cn.stylefeng.guns.modular.tcpconnection.service.DeviceConnectService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 控制器
 *
 * @author gummybear
 * @date 2023/06/29 19:15
 */
@RestController
@ApiResource(name = "")
public class DeviceConnectController {

    @Resource
    private DeviceConnectService deviceConnectService;

    /**
     * 添加
     *
     * @author gummybear
     * @date 2023/06/29 19:15
     */
    @PostResource(name = "添加", path = "/deviceConnect/add")
    public ResponseData<DeviceConnect> add(@RequestBody @Validated(DeviceConnectRequest.add.class) DeviceConnectRequest deviceConnectRequest) {
        deviceConnectService.add(deviceConnectRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除
     *
     * @author gummybear
     * @date 2023/06/29 19:15
     */
    @PostResource(name = "删除", path = "/deviceConnect/delete")
    public ResponseData<?> delete(@RequestBody @Validated(DeviceConnectRequest.delete.class) DeviceConnectRequest deviceConnectRequest) {
        deviceConnectService.del(deviceConnectRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author gummybear
     * @date 2023/06/29 19:15
     */
    @PostResource(name = "编辑", path = "/deviceConnect/edit")
    public ResponseData<?> edit(@RequestBody @Validated(DeviceConnectRequest.edit.class) DeviceConnectRequest deviceConnectRequest) {
        deviceConnectService.edit(deviceConnectRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author gummybear
     * @date 2023/06/29 19:15
     */
    @GetResource(name = "查看详情", path = "/deviceConnect/detail")
    public ResponseData<DeviceConnect> detail(@Validated(DeviceConnectRequest.detail.class) DeviceConnectRequest deviceConnectRequest) {
        return new SuccessResponseData<>(deviceConnectService.detail(deviceConnectRequest));
    }

    /**
     * 获取列表
     *
     * @author gummybear
     * @date 2023/06/29 19:15
     */
    @GetResource(name = "获取列表", path = "/deviceConnect/list")
    public ResponseData<List<DeviceConnect>> list(DeviceConnectRequest deviceConnectRequest) {
        return new SuccessResponseData<>(deviceConnectService.findList(deviceConnectRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author gummybear
     * @date 2023/06/29 19:15
     */
    @GetResource(name = "分页查询", path = "/deviceConnect/page")
    public ResponseData<PageResult<DeviceConnect>> page(DeviceConnectRequest deviceConnectRequest) {
        return new SuccessResponseData<>(deviceConnectService.findPage(deviceConnectRequest));
    }

}
